package br.inf.solutions.apresentacoes.ssp.control.hierarchy;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import br.com.vexillum.model.interfaces.IFilteredSearch;
import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.HierarchyStructType;

@Service
@Scope("prototype")
public class HierarchyUnityController extends HierarchyStructEntityController implements IFilteredSearch {

	private HierarchyStructType type = getHierarchyType("Unidade");
	
	public HierarchyStructType getType() {
		return type;
	}

	public void setType(HierarchyStructType type) {
		this.type = type;
	}

	public Return searchByFilters(){
		String name = (String) data.get("searchKey");
		
		String sql = "FROM HierarchyStructEntity WHERE (type = " + (type == null ? null : getType().getId()) + " or type.name ='" + getType().getName() + "') AND name like '%" + name.toUpperCase() + "%'"; 
		
		data.put("sql", sql);
		
		return searchByHQL();
	}
	
}
